package com.aigou.admin.aigouspringboot.controller.admin;

import com.aigou.admin.aigouspringboot.entity.User;
import com.aigou.admin.aigouspringboot.entity.vo.UserVO;
import com.aigou.admin.aigouspringboot.result.Result;
import com.aigou.admin.aigouspringboot.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author Mr.LiFuXing
 * @Date 2024/12/11 9:10
 * @Title LoginController
 * @Package com.aigou.admin.aigouspringboot.controller
 */

@RestController
@RequestMapping("/admin/user")
public class LoginController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Result<UserVO> login(@RequestBody User user,
                                HttpServletRequest httpServletRequest,
                                HttpServletResponse response) {


        UserVO userVO = userService.login(user, httpServletRequest,response);
        return Result.success(userVO);
    }

    public Result<User> getLoginUser(HttpServletRequest request){

        User user = userService.getLoginUser(request);
        return Result.success(user);
    }
}
